package come.example.pagetransformer.transform

import android.support.v4.view.ViewPager
import android.view.View

class EnhanceDepthPageTransformer : ViewPager.PageTransformer {

    override fun transformPage(page: View, position: Float) {

        if (position < -1 || position > 1) {
            page.alpha = 0f
        } else {
            if (-1 <= position && position < 0) {
                page.alpha = 1 + position - MIN_ALPHA * position

                page.scaleX = 1.0f
                page.scaleY = 1.0f

                page.translationX = 0.0f
            } else if (0 < position && position <= 1) {
                page.alpha = 1 - position + MIN_ALPHA * position

                val scaleFactor = 1 - position + MIN_SCALE * position
                page.scaleX = scaleFactor
                page.scaleY = scaleFactor

                page.translationX = -page.width * position
            } else {
                page.alpha = 1.0f
            }
        }
    }

    companion object {
        private const val MIN_SCALE = 0.75f
        private const val MIN_ALPHA = 0.0f
    }
}
